﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace B4Deal.Models
{
    public class User
    {
        private int maTK = -1;

        public int MaTK
        {
            get { return maTK; }
            set { maTK = value; }
        }
        private string hoTen = string.Empty;

        public string HoTen
        {
            get { return hoTen; }
            set { hoTen = value; }
        }
        private string email = string.Empty;

        public string Email
        {
            get { return email; }
            set { email = value; }
        }
        private string pass = string.Empty;

        public string Pass
        {
            get { return pass; }
            set { pass = value; }
        }
        private string dienThoai = "01225087208";

        public string DienThoai
        {
            get { return dienThoai; }
            set { dienThoai = value; }
        }
        private int loaiTK = 0;

        public int LoaiTK
        {
            get { return loaiTK; }
            set { loaiTK = value; }
        }
        private bool gioiTinh = true;

        public bool GioiTinh
        {
            get { return gioiTinh; }
            set { gioiTinh = value; }
        }
        private DateTime ngaySinh;

        public DateTime NgaySinh
        {
            get { return ngaySinh; }
            set { ngaySinh = value; }
        }
        private int tinhTrang = 0;

        public int TinhTrang
        {
            get { return tinhTrang; }
            set { tinhTrang = value; }
        }
        private List<Order> orders;

        public List<Order> Orders
        {
            get { return orders; }
            set { orders = value; }
        }
        public User(int iMaTK, string iHoTen, string iEmail, string iPass, bool iGioiTinh, DateTime iNgaySinh, int iTinhTrang)
        {
            this.MaTK = iMaTK;
            this.hoTen = iHoTen;
            this.Email = iEmail;
            this.Pass = iPass;
            this.GioiTinh = iGioiTinh;
            this.TinhTrang = iTinhTrang;
            this.NgaySinh = iNgaySinh;
        }
        public User()
        { 
        }
        public List<User> GetUser(int n)
        {
            List<User> users = new List<User>();
            using (var db = new B4Deal_DataEntities())
            {
                var temp = db.TAIKHOANs.ToList().Take(n);
                foreach (var item in temp)
                    users.Add(new User(Convert.ToInt32(item.MaTK), item.HoTen, item.Email, item.Password,Convert.ToBoolean(item.GioiTinh), Convert.ToDateTime(item.NgaySinh), Convert.ToInt32(item.TinhTrang)));
                return users;
            }
        }
    }
}